package com.shopping.category;
import java.util.ArrayList;
import java.util.List;

import com.shopping.category.CategoryDAO;

public class Category {
	private int id;
	private String name;
	private String descr;
	private int pid;
	private boolean cno;
	private int grade;
	
	public boolean isCno() {
		return cno;
	}

	public void setCno(boolean cno) {
		this.cno = cno;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescr() {
		return descr;
	}

	public void setDescr(String descr) {
		this.descr = descr;
	}

	public int getPid() {
		return pid;
	}

	public void setPid(int pid) {
		this.pid = pid;
	}

	

	public int getGrade() {
		return grade;
	}

	public void setGrade(int grade) {
		this.grade = grade;
	}
	
	public static List<Category> getCategories() {
		List<Category> list = new ArrayList<Category>();
		CategoryDAO.getCategories(list,0);
		return list;
	}
	
	public static void add(Category c) {
		CategoryDAO.save(c);
	}
	
	public static void addChild(Category c) {
		Category.addChildCategory(c.getId(),c.getName(), c.getDescr());
	}
	
	public static void addTopCategory(String name,String descr) {
		
		Category c = new Category();
		c.setId(-1);
		c.setName(name);
		c.setDescr(descr);
		c.setPid(0);
		c.setCno(true);
		c.setGrade(1);
		CategoryDAO.save(c);
		
		//add(c);
		
		//addChildCategory(0,name,descr);
	}
	
	public static void addChildCategory(int pid,String name,String descr) {
		CategoryDAO.addChildCategory(pid,name,descr);
		System.out.println(pid);
	}
	
	public static Category loadId(int id) {
		return CategoryDAO.loadById(id);
	}
	
	public static void deleteCategory(int id) {
		CategoryDAO.deleteCategories(id);
	}
}

